package likou;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/04/30 08:44
 */
public class _137 {
    public int singleNumber(int[] nums) {
        Map<Integer,Integer> map = new HashMap<>();
        for(int i :nums){
            map.put(i,map.getOrDefault(i,0)+1);
            if(map.get(i)==3){
                map.remove(i);
            }
        }
        Set<Integer> set = map.keySet();
        Integer res = 0;
        for (Integer i:set){
            res = i;
        }
        return res;
    }
    public static int singleNumber2(int[] nums) {
        int a = 0, b = 0;
        for (int num : nums) {
            a = (a ^ num) & ~b;
            b = (b ^ num) & ~a;
        }
        return a;
    }

    public static void main(String[] args) {
        singleNumber2(new int[]{2,2,3,2});
    }
}
